<?php

/*
  Initialization script

  Author:     Alfredo Mungo
  License:    LGPL
  Copyright:  2012

 */

define('PHI_ROOTDIR', getcwd()); // Framework directory in file system coordinates
define('PHI_SERVDIR', substr(PHI_ROOTDIR, strlen($_SERVER['DOCUMENT_ROOT']))); // Framworkd directory in server relative coordinates

{ // PHP version
  $str_version = phpversion();
  $version = explode('.', $str_version);
    
  define('PHI_PHP_MAJOR', $version[0]);
  define('PHI_PHP_MINOR', $version[1]);
  define('PHI_PHP_RELEASE', $version[2]);
}

{ // PHP version-dependant features
  if(PHI_PHP_MAJOR >= 5 && PHI_PHP_MINOR >= 4)
    define('PHI_PHP_SCANDIR_CONSTANTS', true);
  else
    define('PHI_PHP_SCANDIR_CONSTANTS', false);
    
}

// Load settings
$settings = array('basic' /*, 'credentials' */); //Add settings (without extension) to be loaded from the 'settings' folder here.

foreach ($settings as $setting)
  include_once PHI_ROOTDIR . "/settings/$setting.php";

unset($settings);
///

require_once "core/core.php"; // Core library

// Hook system initialization
HookManager::init();
///

if(PHI_PLUGINS) { // Plugins enabled, load'em
    
  if(PHI_PHP_SCANDIR_CONSTANTS)
    $plugins = @scandir(PHI_ROOTDIR . '/plugins/', SCANDIR_SORT_NONE);
  else
    $plugins = @scandir(PHI_ROOTDIR . '/plugins/');
    
  if($plugins !== false)
    foreach($plugins as $plugin)
      if(substr($plugin, -4) == '.php') // is a PHP file?
	include PHI_ROOTDIR . '/plugins/' . $plugin;
}

// Enable debug/non-debug features
if(PHI_DEBUG) {
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
    
  // debug hooks
  HookManager::run(HookManager::HOOK_DEBUG);
}
else {
  error_reporting(0);
  ini_set('display_errors', '0');
    
  // release hooks
  HookManager::run(HookManager::HOOK_RELEASE);
}
///

?>